
load('summary_data/figA8.rda')
source('utils.R')

ga = rbindlist(list(r12a, r16a, r20a)) %>%
  ggplot(aes(
    x = nat_quant,
    y = sq,
    fill = class,
    group = class,
    color = class
  )) +
  geom_point() + geom_line() +
  theme_light() +
  scale_x_discrete(labels = x_l) +
  scale_y_continuous(labels = scales::label_percent(), limits = c(0, .6)) +
  labs(
    x = element_blank(),
    y = element_blank(),
    fill = element_blank(),
    title = 'GOP Primary Donor Conversion'
  ) +
  scale_fill_manual(values = c("chocolate1", "brown1", "darkred")) +
  scale_color_manual(values = c("chocolate1", "brown1", "darkred")) +
  theme(
    legend.position = 'top',
    axis.text.x = element_text(
      angle = 25,
      vjust = .8,
      hjust = 0.5,
      size = 8
    )
  ) +
  guides(fill = 'none',
         color = guide_legend(title = element_blank(), ncol = 1)) +
  theme(text = element_text(face = 'bold'))

gb = rbindlist(list(r12b, r16b, r20b)) %>%
  ggplot(aes(
    x = nat_quant,
    y = sq,
    fill = class,
    group = class,
    color = class
  )) +
  geom_point() + geom_line() +
  theme_light() +
  scale_x_discrete(labels = x_l) +
  scale_y_continuous(labels = scales::label_percent(), limits = c(0, .6)) +
  labs(
    x = element_blank(),
    y = element_blank(),
    fill = element_blank(),
    title = 'GOP Congressional Cross-Cycle Retention'
  ) +
  scale_fill_manual(values = c('#333333', '#7f7f7f', '#cccccc')) +
  scale_color_manual(values = c('#333333', '#7f7f7f', '#cccccc')) +
  theme(
    legend.position = 'top',
    axis.text.x = element_text(
      angle = 25,
      vjust = .8,
      hjust = 0.5,
      size = 8
    )
  ) +
  guides(fill = 'none',
         color = guide_legend(title = element_blank(), ncol = 1)) +
  theme(text = element_text(face = 'bold'))

out = plot_grid(
  ga,
  gb,
  nrow = 1,
  labels = str_c('(', LETTERS[1:2], ')'),
  label_x = -.025,
  label_y = 1
)

ggsave(filename = 'figures/figA8.pdf', plot = out, width = 9, height = 4, units = 'in')
